export function createReducer (initialState, actionHandlers) {
  return (state = initialState, action) => {
    const reduceFn = actionHandlers[action.type]
    if (!reduceFn) return state
    // Looks it works like Object.assign
    return { ...state, ...reduceFn(state, action) }
  }
}

export function dateToString(date) {
  let oDate = new Date(date) == "Invalid Date" ? new Date(Number(date)) : new Date(date),
    sYear = oDate.getFullYear(),
    sMonth = oDate.getMonth() + 1,
    sDate = oDate.getDate(),
    sHour = oDate.getHours(),
    sMinutes = oDate.getMinutes(),
    sSeconds = oDate.getSeconds();
    sSeconds = sSeconds < 10 ? '0'+sSeconds : sSeconds;
  return  sYear+ '-' + sMonth + '-' + sDate + ' ' + sHour + ':' + sMinutes + ':' + sSeconds;
}